package io.github.fb513.api.util;

import io.github.fb513.api.enums.RespMetaEnum;
import io.github.fb513.api.model.CommonResp;
import io.github.fb513.api.model.PageInfo;
import lombok.Getter;

import java.util.Collections;
import java.util.List;

@Getter
public class RespUtils {

    public static CommonResp<?> success() {
        return success(null);
    }

    public static <T> CommonResp<T> success(T data) {
        return new CommonResp<>(RespMetaEnum.SUCCESS.getStatus(), RespMetaEnum.SUCCESS.getMsg(), data);
    }

    public static <T> CommonResp<List<T>> success(int pageNum, int pageSize) {
        PageInfo pageInfo = new PageInfo(pageNum, pageSize);
        CommonResp<List<T>> resp = new CommonResp<>(RespMetaEnum.SUCCESS.getStatus(), RespMetaEnum.SUCCESS.getMsg(), Collections.emptyList());
        resp.setPageInfo(pageInfo);
        return resp;
    }

    public static <T> CommonResp<T> success(String msg, T data) {
        return new CommonResp<>(RespMetaEnum.SUCCESS.getStatus(), msg, data);
    }

    public static <T> CommonResp<T> warning(RespMetaEnum meta) {
        return new CommonResp<>(meta.getStatus(), meta.getMsg(), null);
    }

    public static CommonResp<?> warning(int status, String msg) {
        return new CommonResp<>(status, msg, null);
    }
}
